{% extends "sentry/bases/account.html" %}

{% load crispy_forms_tags %}
{% load i18n %}
{% load sentry_auth %}
{% load sentry_helpers %}

{% block title %}{% trans "Subscriptions" %} | {{ block.super }}{% endblock %}

{% block main %}
    {% if not email.is_verified %}
      <div class="alert alert-warning alert-block">
        {% trans "Your email address has not been verified. " %}
        <form action="{% url 'sentry-account-confirm-email-send' %}" method="post" class="email-alert-button">
          {% csrf_token %}
          <input type="hidden" name="email" value="{{ email.email }}">
          <button type="submit" name="primary-email" class="btn-link">{% trans "Resend Verification Email." %}</button>
        </form>
      </div>
    {% endif %}

    <legend class="m-t-0">Subscriptions</legend>
    {% for subscription in subscriptions.subscriptions %}
        <div class="row p-b-1">
            <div class="col-md-9">
                <h5>{{ subscription.list_name }}</h5>
            </div>
            <div class="col-md-3 align-right" style="padding-right: 25px">
                <div data-list-id="{{ subscription.list_id }}" class="switch switch-lg{% if subscription.subscribed %} switch-on{% endif %}" role="checkbox">
                    <span class="switch-toggle"></span>
                </div>
            </div>
        </div>
    {% endfor %}

    <script>
    $('div.switch').click(function(){
        var $e = $(this);
        $e.toggleClass('switch-on');
        $.post('{% url 'sentry-account-settings-subscriptions' %}', {
            'subscribed': $e.hasClass('switch-on') ? '1' : '0',
            'listId': $e.data('list-id')
        });
    });
    </script>
{% endblock %}
